const KoaRouter = require('koa-router');
const Template = require('../util/Template');
const HttpClient = require('../util/HttpClient')

const modules = require('../../modules');
const router = new KoaRouter();

// 呼叫中心设置
// router.get('/setting/callcenter/setting/:type', async ctx => {
//   let script = ['/callcenter.index.js'];
//   let modConfig = modules['callcenter.index'];
//   let reqHeaders = ctx.request.headers;

//   let result = await HttpClient.request(`/setting/callcenter/setting/${ctx.params.id}`, 'get', null, {headers: reqHeaders});
//   let body = result.body;

//   ctx.body = await Template.renderWithHtml('呼叫中心设置', body, script, modConfig.template, ctx)
// })

// 呼叫中心
router.get('/setting/callcenter/stage', async ctx => {
  let script = ['/callcenter.stage.js'];
  let modConfig = modules['callcenter.stage'];
  let reqHeaders = ctx.request.headers;
  
  let result = await HttpClient.request('/setting/callcenter/stage', 'get', null, {headers: reqHeaders});
  let body = result.body;

  ctx.body = await Template.renderWithHtml('呼叫中心', body, script, modConfig.template, ctx)
})

// 呼叫中心
router.get('/setting/callcenter/stage', async ctx => {
  let script = ['/callcenter.stage.js'];
  let modConfig = modules['callcenter.index'];
  let reqHeaders = ctx.request.headers;

  let result = await HttpClient.request(`/setting/callcenter/stage`, 'get', null, {headers: reqHeaders});
  let body = result.body;
  
  ctx.body = Template.renderWithHtml('呼叫中心', body, script, modConfig.template)
})

// 呼叫中心通话记录详情
router.get('/setting/callcenter/view', async ctx => {
  let script = ['/callcenter.view.js'];
  let modConfig = modules['callcenter.view'];
  let reqHeaders = ctx.request.headers;

  let result = await HttpClient.request(`/security/user/list/${ctx.params.id}`, 'get', null, {headers: reqHeaders});
  let body = result.body;
  
  ctx.body = await Template.renderWithHtml('通话详情', body, script, modConfig.template, ctx)
})

// 呼叫工作台
router.get('/setting/callcenter/workbench', async ctx => {
  let script = ['/callcenter.workbench.js'];
  let modConfig = modules['callcenter.workbench'];
  let reqHeaders = ctx.request.headers;

  let result = await HttpClient.request('/setting/callcenter/workbench', 'get', null, {headers: reqHeaders});
  let body = result.body;
  
  ctx.body = await Template.renderWithHtml('呼叫工作台', body, script, modConfig.template, ctx)
})

module.exports = router;